package com.hmall.search.service.impl;

import com.hmall.api.client.ItemClient;
import com.hmall.api.domain.dto.ItemDTO;
import com.hmall.common.domain.query.ItemPageQuery;
import com.hmall.common.domain.PageDTO;


import com.hmall.search.service.ISearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.stereotype.Service;

/**
 * @Author macro
 * @Date 2025/7/3  12:43
 * @Description 搜索服务实现类
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class SearchServiceImpl implements ISearchService {

    private final RestHighLevelClient client;
    private final ItemClient itemClient;

    @Override
    public PageDTO<ItemDTO> search(ItemPageQuery query) {
        // TODO: 这里先调用商品服务，后续替换为ES搜索
        // 临时方案：通过Feign调用商品服务
        log.info("执行商品搜索，关键字：{}", query.getKey());
        
        // 将来这里会是ES查询逻辑
        // 当前先通过Feign调用item-service保持功能不变
        return itemClient.searchItems(query);
    }
} 